package Demo1.a02demo2;

import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("请输入一串字符串");
            String s = sc.nextLine();
            boolean flag = check(s);
            if (flag) {
                int num = Integer.parseInt(s);
                System.out.println(num);
                break;
            }
        }
    }

    private static boolean check(String s) {
        if (s.startsWith("0")) {
            return false;
        }
        if (s.length() < 1 || s.length() > 10) {
            return false;
        }
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (!(c >= '0' && c <= '9')) {
                return false;
            }
        }
        return true;
    }
}
